﻿@{
    Layout = "~/Views/Shared/_level1.cshtml";
    if (false)
    {
        <script src="/LiberUI/Scripts/jquery.js"></script>
        <script src="/LiberUI/Scripts/LiberUI.Base.js"></script>
        <script src="/LiberUI/Scripts/LiberUI.js"></script>
        <script src="/LiberUI/Scripts/LiberUI.Action.js"></script>
    }
    <link href="/SiteUI/MyBiz/Find.css" rel="stylesheet" />

}
<title>天联云-发现</title>
<div class="col-lg-7" id="search">
    <div class="row" id="findCnds">
        <div class="col-lg-3" id="logoFinder"><img src="/SiteUI/Imgs/logo-finder.png" /></div>
        <input class="col-lg-7" id="findKey" placeholder="订货日期/订单编号/联系人名称/手机号/公司名称" />
        <div class="col-lg-2 button" id="btnGoSearch">搜索</div>
    </div>
    <div class="row" id="findResult">

    </div>
</div>
<div class="col-lg-5" id="guid">

</div>
<script id="tplOrderItem" type="text/html">
    <!--待确认新订单列表项模板-->
    <div class="row ordItem">
        <div class="col-lg-10 oi-head">
            <span>交易编号：</span><span>{{d.idstr}}</span>
        </div>
        <div class="col-lg-2 oi-head">
            <a target="_blank" href="/Trade/OrderDetail?oid={{d.idstr}}">查看订单详情>></a>
        </div>
        <div class="col-lg-4 oi-orderInfo">
            <span>订单编号：{{d.src_orderserial||'-'}}[{{d.src_orderversion}}]</span>
            <br />
            <span>订货日期：{{d.orderdate}}</span>
            <br />
            <span>交货日期：{{d.deliverydate}}</span>
        </div>
        <div class="col-lg-4 oi-company">
            <a href="#" class="Company {{(d.client_id)?'certificated':'no-certificated'}}">{{d.client_realname||d.src_client}}</a>
            <br />
            <span>联系人：</span><a href="#" class="People {{(d.buyer_id)?'certificated':'no-certificated'}}">{{d.buyer||d.src_buyer}}&nbsp;&nbsp;{{d.buyer_phone||d.src_buyerphone}}</a>
            <br />
            <span>收货人：</span><a href="#" class="People {{(d.consignee_id)?'certificated':'no-certificated'}}">{{d.src_consignee||d.consignee}}&nbsp;&nbsp;</a>
            <br />
            <span>联系电话：{{d.consignee_phone||d.src_consigneephone}}</span>
        </div>
        <div class="col-lg-4 oi-company">
            <a href="#" class="Company {{(d.supplier_id)?'certificated':'no-certificated'}}">{{d.supplier_realname||d.src_supplier}}</a>
            <br />
            <span>联系人：</span><a href="#" class="People {{(d.saler_id)?'certificated':'no-certificated'}}">{{d.saler||d.src_saler}}&nbsp;&nbsp;</a>
            <br />
            <span>联系电话：{{d.saler_phone||d.src_salerphone}}</span>
        </div>
    </div>
</script>
<script>
    Find = {
        lstOrder: null,
        tplOrder: null,
        GoSearch: function () {
            var k = $("#findKey").vl().trim();
            Find.lstOrder.vl(null).update().Loading("正在搜索...");
            $.getJSON("/Trade/FindOrder", { key: k }, Find.SearchEnd);
        },
        SearchEnd: function (rtn) {
            if (rtn.IsPositive) {
                if (rtn.Data.Orders.length > 0) {
                    Find.lstOrder.vl(rtn.Data.Orders).update();
                }
            }
            Find.lstOrder.update();
        },
        makeOrderView: function ($item, od) {
            var k = $("#findKey").vl().trim();
            od.client_logo = od.client_logo || "/UserFile/DefaultCompanyLogo.gif";
            od.client = od.client_realname || od.invoiceheading;
            od.buyer = od.buyer || od.src_buyer;
            od.consignee_displayname = od.src_consignee || od.consignee_realname;
            od.orderdate = new Date(od.src_orderdate || od.createtime).toString();
            od.deliverydate = new Date(od.src_deliverydate || od.deliverydate).toString();
            od.urgent = daysBetween(new Date(od.src_deliverydate || od.deliverydate).toString(), new Date().toString()) < 5;
            od.amountStr = od.amount.roundTo(2).toThousands();
            od.taxrate = od.taxrate + "%";
            var v = Find.tplOrder.render(od);          
            try {
                var rg = new RegExp(k, "gi");
                v = v.replace(rg, "<mark>" + k + "</mark>");
            }
            catch (ex) {

            }
            $item.append($(v).addClass("fladeInUp"));
        }
    };

    $(function () {
        var key = getUrlParam("key");

        KeybordHelper.on($("#findKey"), "enter", Find.GoSearch);
        $("#btnGoSearch").on("click", Find.GoSearch);
        Find.lstOrder = new LiberUI.Lister("#findResult")
                                   .option("ContentRender", Find.makeOrderView);
        Find.tplOrder = laytpl($("#tplOrderItem")[0].innerHTML);
        if (key) {
            $("#findKey").vl(key);
            Find.GoSearch();
        }
    })
</script>


